/**
 * @name AlgorithmDemo2
 * @class name：PACKAGE_NAME
 * @class describe
 * @anthor jin
 * @time 2020/8/22 20:32
 * @change
 * @chang time
 */
class Test implements Runnable {

  public static void main(String[] args) {
    Test test = new Test();
    Test test2 = new Test();
    Thread thread = new Thread(test);
    Thread thread1 = new Thread(test2);
    thread.start();
    thread1.start();
    try {
      thread.join();
      thread1.join();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    System.out.println("aaa---" + a);
  }

  private static Object lock = new Object();
  private static int a = 0;

  @Override
  public void run() {
    for (int i = 0; i < 10000; i++) {
      //
      increat();
    }
  }

  private void increat() {
    synchronized (lock) {
      a++;
    }
  }
}
